

<div id='FreeOrder_MainArea'>
	
	<h2 style='text-align:center'>砍价订单管理</h2>

	<div style='margin:5px 0;display:flex;height:26px;border:0px solid'>
		<div style='flex:1'>
			<input placeholder='订单号搜索' id='FreeOrder_SearchInp' type="text" style='border-radius:5px;width:100%;height:100%' />
		</div>
		<div id='FreeOrder_SearchBtn' style='border-radius:5px;width:40px;height:100%;box-sizing:border-box;padding:3px 10px;background:#eee'><img src='../Public/Image/search.png' style='height:20px' alt="" /></div>
	</div>
	<div>
		<select style='width:100%' id="FreeOrder_SelType" >
			<option value="2">待领取</option>
			<option value="3">已完结</option>
		</select>
	</div>

	<div id='FreeOrderList'>
		<div style='display:flex;border-bottom:7px solid #fee;font-size:13px;margin:15px 0;'>
			<div style='border:1px solid #eef;width:100px;height:100px'>
				<img src='../Public/Image/base.png' style='width:100%;height:100%' onerror=this.src='../Public/Image/base.png' alt='呵呵了' >
			</div>
			<div style='flex:1;padding:0 5px;box-sizing:border-box;color:#999'>
				<div style='font-size:14px;padding:2px 0;word-break:break-all;overflow:hidden;color:#333'>
					题标题标题标题标题标题标题标题标题标题标题标题标题标题
				</div>	
				<div style='padding:3px 0'>
					<span style='color:blue'>￥：382元</span>
					<span style='float:right;color:red'>已砍：382元</span>
				</div>
				<div style='padding:3px 0'>
					<span style='color:green'>状态：砍价中</span>
					<span style='margin-left:10px;color:#fff;background:#aaf;padding:1px 5px;border-radius:5px' >查看详情</span>
				</div>
			</div>
		</div>
	</div>
</div>

<div id='FreeOrder_DetailArea' style='display:none'>
	<h2 style='text-align:center'>订单详情</h2>
	<div id='FreeOrder_DetailArea1' style='margin-bottom:30px'></div>
	<div id='FreeOrder_DetailArea2'>
		<!--div style='display:flex;font-size:12px;line-height:35px;margin:10px auto'>
			<div style='border-radius:25px;width:35px;height:35px;overflow:hidden'><img src="http://tp-shop-img.bm123.club/shop_img/110101/a1a1/10/20200602211428.jpg" style='width:100%;height:100%' ></div>
			<div style='flex:1;width:100px;border:0px solid;white-space:nowrap;overflow:hidden'>　震彩云追月</div>
			<div style=''>　砍 18.95</div>
			<div style=''>　12:22:32</div>
		</div-->
	</div>

	<div style='margin:20px auto;text-align:center'><button onclick='_FreeOrderDetailBack()'>返回</button></div>
	
</div>


<div style='text-align:center;margin:30px 0;display:none' id='backToControFreeBtn'>
	<button onclick='_backToControFree()'>返回砍价商品管理</button>
</div>

<script>

var orderList = [];	//订单列表窗口
var currentOrder = []; 	//当前选择的订单信息窗口

_countrolFreeInit();	//页面初始化

//页面初始化
function _countrolFreeInit(){
	_checkViewBackToControFreeBtn();	//判断是否从砍价商品页跳转而来
	_FreeOrderView();	//获取并展示订单列表
}

//判断是否从砍价商品页跳转而来
function _checkViewBackToControFreeBtn(){
	if(sessionStorage.admin_formFreeGoodsId){
		$('#backToControFreeBtn').show();
	}else{
		$('#backToControFreeBtn').hide();
	}
}



//返回砍价商品管理页
function _backToControFree(){
	$('#backToControFreeBtn').hide();
	sessionStorage.admin_formFreeGoodsId = '';
	$('#Main_Nav').val('Main_FreeGoods');
	_loadPage();
}





//返回订单列表页
function _FreeOrderDetailBack(){
	_checkViewBackToControFreeBtn();
	$('#FreeOrder_MainArea').show();
	$('#FreeOrder_DetailArea').hide();
}


//查看详情
function _showDetail(index){
	$('#backToControFreeBtn').hide();
	currentOrder[0] = orderList[index];
	$('#FreeOrder_MainArea').hide();
	$('#FreeOrder_DetailArea').show();
	_getFreeOrderListForStoreParse(currentOrder,'#FreeOrder_DetailArea1');

	_getFreeOrderUser(currentOrder[0].id);	//获取帮砍用户信息

}

//获取帮砍用户信息
function _getFreeOrderUser(order_id){
	var data = {
		type:'getFreeOrderUser',
		order_id:order_id
	}
	AjaxAdmin(data,function(res){
		var tmp = _checkJsonFormat(res,1);
		_getFreeOrderUserParse(tmp.data)
	});
}

//解析帮砍用户列表
function _getFreeOrderUserParse(uList){
	var tmp_str = '';
	for(var i=0;i<uList.length;i++){
		tmp_str += "<div style='display:flex;font-size:12px;line-height:35px;margin:10px auto'>";
			tmp_str += "<div style='border-radius:25px;width:35px;height:35px;overflow:hidden'><img src='' srcs='"+uList[i].header+"' style='width:100%;height:100%' ></div>";
			tmp_str += "<div style='flex:1;width:100px;border:0px solid;white-space:nowrap;overflow:hidden'>　"+uList[i].name+"</div>";
			tmp_str += "<div style=''>　砍 "+uList[i].price+"</div>";
			var tmpTime = StampToYmd(uList[i].ftime*1000,2);
			tmp_str += "<div style=''>　"+tmpTime+"</div>";
		tmp_str += "</div>";
	}
	$('#FreeOrder_DetailArea2').html(tmp_str);

	Img_Later_View3('#FreeOrder_DetailArea2');	//图片懒加载
}



//搜索
$('#FreeOrder_SearchBtn').click(function(){
	_FreeOrderView();
});


//类型切换
$('#FreeOrder_SelType').change(function(){
	_FreeOrderView();
})


//获取并展示订单列表
function _FreeOrderView(){
	_getFreeOrderListForStore(function(res){
		_getFreeOrderListForStoreParse(res);
	});
}



/*
	### 获取指定商户的砍价订单
	注：该数据因为是商户端数据，应该不像前端那样多用户操作，基本会固定在几个终端上使用的。所以该数据的缓存不适用upyun,而适用于本地缓存 localStorage,及定时刷新和搜索追加的方式进行缓存

*/
function _getFreeOrderListForStore(fun){
	var search = $('#FreeOrder_SearchInp').val().trim();
	if(search && !/^[0-9]+$/.test(search)){
		A('订单号有误！');return;
	}
	var data = {
		type:'getFreeOrderListForStore',
		selType:$('#FreeOrder_SelType').find('option:selected').val(),
		search:search,
		freeGoodsId:sessionStorage.store_formFreeGoodsId		//查询指定砍价商品下的关联订单时使用
	}
	AjaxAdmin(data,function(res){
		var tmp = _checkJsonFormat(res,1);
		orderList = tmp.data;
		fun(tmp.data);
	});
}

// ele 元素的id名 如：'#id'
function _getFreeOrderListForStoreParse(res,ele){
	var str = '';

	for(var i = 0;i<res.length;i++){
		if(/^\/.*\.jpg$/.test(res[i].banner)){
			var banner_src = upyun_shop_img + res[i].banner;
		}else{
			var banner_src = '../Public/Image/base.png';
		}
		str += "<div style='display:flex;border-bottom:7px;font-size:13px;margin:15px 0;'>";
		str += "<div style='border:1px solid #eef;width:100px;height:100px'>";
			str += "<img src='' srcs='"+banner_src+"' style='width:100%;height:100%' onerror=this.src='../Public/Image/base.png' alt='呵呵了' >";
		str += "</div>";
		str += "<div style='flex:1;padding:0 5px;box-sizing:border-box;color:#999'>";
			str += "<div style='font-size:14px;padding:2px 0;word-break:break-all;overflow:hidden;color:#333'>名称：" + res[i].title + "</div>";
			str += "<div style='font-size:14px;padding:2px 0;word-break:break-all;overflow:hidden;color:#333'>订单号：" + res[i].order_numb + "</div>";
			str += "<div style='padding:3px 0'>";
				str += "<span style='color:blue'>￥："+res[i].price+"元</span>";
				//创建时间
				var ctimev = StampToYmd(res[i].ctime*1000,1);
				str += "<span style='float:right;color:#380'>"+ctimev+"</span>";
			str += "</div>";
			str += "<div style='padding:3px 0'>";
				switch(res[i].stat){
					case 1:case'1':var statv = '<span style="color:#77e">砍价中</span>';break;
					case 2:case'2':var statv = '<span style="color:red">待领取</span>';break;
					case 3:case'3':var statv = '<span style="color:#0cc">已完结</span>';break;
					case 4:case'4':var statv = '<span style="color:#cc0">已作废</span>';break;
				}
				str += "<span style='color:green'>状态：" + statv + "</span>";
				if(!ele){
					str += "<span style='margin-left:10px;color:#fff;background:#aaf;padding:1px 5px;border-radius:5px' onclick='_showDetail(" + i + ")'>查看详情</span>";
				}
			str += "</div>";
		str += "</div></div>";
	}
	if(ele){
		$(ele).html(str);
		Img_Later_View3(ele);	//图片懒加载
	}else{
		$('#FreeOrderList').html(str);
		Img_Later_View3('#FreeOrderList');	//图片懒加载
	}

}


</script>